import { NextRequest, NextResponse } from "next/server";
import prisma from "../../../lib/prisma";

export async function POST(request: NextRequest) {
  try {
    const { email } = await request.json();

    // 查找用户
    let user = await prisma.user.findUnique({
      where: { email },
    });

    // 未找到则创建
    if (!user) {
      user = await prisma.user.create({
        data: { email },
      });
    }

    return NextResponse.json({ user });
  } catch (error) {
    return NextResponse.json({ error: "服务端 error" }, { status: 500 });
  }
}
